<?php
//classes must start with a capital letter and the filename must be the class name with all lowercase
class Main extends MY_Controller {

	//add variables here

	//required constructor
	public function __construct()
	{
		parent::__construct();
		
		$this->load->model('User_model', 'user');
		$this->load->model('Board_model', 'board');
		$this->load->model('Thread_model', 'thread');
	}
	
	//when the view controller is loaded, index always gets called automatically (after constructor obv)
	public function index()
	{
		$this->data['board_list'] = $this->populate_thread_count( $this->board->get_all() );
		
		$this->data['main_content_view'] = $this->load->view('main_view', $this->data, true);
		$this->load->view('default', $this->data);
	}
	
	private function populate_thread_count( $board_list )
	{
		foreach( $board_list as &$board )
		{
			$board['ThreadNum'] = strval(count($this->thread->get_board_threads( $board['BoardID'] )));
		}
		
		return $board_list;
	}
	
	public function signOut()
	{
		$this->session->sess_destroy();
		$this->session->unset_userdata('userID');
		$this->session->unset_userdata('my_session_id');
		redirect('/SignIn');
	}
}

?>